core: Increase type safety of some local alloc functions
authorColin Walters <walters@verbum.org>
Thu, 3 May 2012 17:26:24 +0000 (13:26 -0400)
committerColin Walters <walters@verbum.org>
Thu, 3 May 2012 20:05:53 +0000 (16:05 -0400)
src/libotutil/ot-local-alloc.c
src/libotutil/ot-local-alloc.h

index ab62e0d8cd6f5e6bf2f8c4578e8dfcbb5a655c54..cf1dba32c60c232ef6f9fcf1918b7fd108d15a43 100644 (file)
@@ -45,23 +45,28 @@ ot_local_free (void *loc)
 void
 ot_local_obj_unref (void *loc)
 {
-  _ot_local_free(GObject, g_object_unref);
+  GObject **location = (GObject**)loc;
+  if (location && *location)
+    g_object_unref (*location);
 }
 
 void
-ot_local_variant_unref (void *loc)
+ot_local_variant_unref (GVariant **loc)
 {
-  _ot_local_free(GVariant, g_variant_unref);
+  if (loc && *loc)
+    g_variant_unref (*loc);
 }
 
 void
-ot_local_ptrarray_unref (void *loc)
+ot_local_ptrarray_unref (GPtrArray **loc)
 {
-  _ot_local_free(GPtrArray, g_ptr_array_unref);
+  if (loc && *loc)
+    g_ptr_array_unref (*loc);
 }
 
 void
-ot_local_hashtable_unref (void *loc)
+ot_local_hashtable_unref (GHashTable **loc)
 {
-  _ot_local_free(GHashTable, g_hash_table_unref);
+  if (loc && *loc)
+    g_hash_table_unref (*loc);
 }
index 2aeea7573384b8f1c40e88b0a8e010adef3f6908..3cbfc528dd5d56c788b15b6ca80be5e04b518c7f 100644 (file)
@@ -29,9 +29,9 @@ G_BEGIN_DECLS
 
 void ot_local_free (void *loc);
 void ot_local_obj_unref (void *loc);
-void ot_local_variant_unref (void *loc);
-void ot_local_ptrarray_unref (void *loc);
-void ot_local_hashtable_unref (void *loc);
+void ot_local_variant_unref (GVariant **loc);
+void ot_local_ptrarray_unref (GPtrArray **loc);
+void ot_local_hashtable_unref (GHashTable **loc);
 
 #define ot_lfree __attribute__ ((cleanup(ot_local_free)))
 #define ot_lobj __attribute__ ((cleanup(ot_local_obj_unref)))